package cn.doctorpda.conference.update;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * 更新的工具类
 * Created by jiangxiufeng on 16/8/5.
 */
public class BaiyyyUpdateUtils {

    public static int getVerisionCode(Context context) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return -1;
    }


    public static void setVersionCode(Context context,int versionCode) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(BaiyyyUpdateConfig.UPDATE_PREF, Activity.MODE_PRIVATE);
        sharedPreferences.edit().putInt(BaiyyyUpdateConfig.VERSION_CODE_KEY, versionCode).apply();
    }

    public static int getVersionCode(Context context) {
        SharedPreferences sharedPreferences =context.getSharedPreferences(BaiyyyUpdateConfig.UPDATE_PREF, Activity.MODE_PRIVATE);
        return sharedPreferences.getInt(BaiyyyUpdateConfig.VERSION_CODE_KEY,0);
    }

}
